package com.starsky.common.web;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * Entity基类
 *
 * @author kyson
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
public class BaseVo implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 当前页码
     */
    private Integer pageNum;
    /**
     * 每页显示记录数
     */
    private Integer pageSize;
    /**
     * 每页显示记录数
     */
    private Integer startIndex;

    /**
     * 开始时间
     */
    private String beginTime;

    /**
     * 结束时间
     */
    private String endTime;
    /**
     * 排序字段
     */
    private String orderField;

    /**
     * 排序方式(ASC,DESC)
     */
    private String order;

    public String getOrderField() {
        return orderField;
    }

    public void setOrderField(String orderField) {
        this.orderField = orderField;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Integer getPageNum() {
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        this.pageNum = pageNum;
        return this.pageNum;
    }

    public void setPageNum(Integer pageNum) {
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        if (pageSize == null || pageSize <= 0) {
            pageSize = 10;
        }
        this.pageSize = pageSize;
        return this.pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if (pageSize == null || pageSize <= 0) {
            pageSize = 10;
        }
        this.pageSize = pageSize;
    }

    public Integer getStartIndex() {
        this.startIndex = (this.getPageNum() - 1) * this.getPageSize();
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        if (startIndex == null || startIndex <= 0)
            startIndex = (this.getPageNum() - 1) * this.getPageSize();
        this.startIndex = startIndex;
    }
}
